package org.marverse.universe.messages

import persistance.PId
import scripting.{Type, Function, FunctionType, TupleType, TupleValue}
import scripting.ScriptingUtil._

/**
 * The type of a {@link Message}.
 */
object MessageType extends Type {
  override def toString = "message"
  override def memberDeclarations = Seq.empty
  override def isInstance(v: Any) = v.isInstanceOf[Message]
}

/**
 * A locale independent representation of text.
 * @see MessageType
 */
case class Message(val template: MessageTemplate, val argument: TupleValue) {

}

/**
 * A locale independent template for generating messages.
 */
case class MessageTemplate(val pid: PId, argumentType: TupleType) extends Function {
  
  override def apply(argument: Any)(implicit ctx: MutableTypedMap[TypedKey, Any]) = {
    assert(argumentType.isInstance(argument))
    Message(this, argument.asInstanceOf[TupleValue])
  }
    
}